Learn R Programming

VeryLargeIntegers (version 0.2.1)

14. Finding a random divisor: Finding a Random Divisor of a vli Object

Description

divisor returns a randomly chosen divisor of a given number.

Usage

divisor(n, iter = 100)

# S3 method for default divisor(n, iter = 100)

# S3 method for numeric divisor(n, iter = 100)

# S3 method for vli divisor(n, iter = 100)

Value

object of class vli

Arguments

n

object of class vli or 32 bits integer

iter

number of iterations for testing if the given number is prime; numeric

Author

Javier Leiva Cuadrado

Details

The algorithm determines if the given number is prime or composite by usign the Miller-Rabin Probabilistic Primality Test. If it is prime, it returns the number itself. If it is composite, it returns a randomly chosen divisor. The number of iterations is configurable to set the desired accuracy. A too low number of iterations could cause an infinite loop because of being looking for a divisor of a prime number.

Examples

Run this code
r <- rvliprime(100)
r
x <- r * 51
x
divisor(x, iter = 100)

Run the code above in your browser using DataLab